<?php
include_once('/var/www/html/new/com.inc.php');
include_once '/var/www/html/new/d/module/common/Db.class.php';
$dbConf = include '/var/www/html/new/d/module/common/db.conf.php';// 远端服务器配置信息


if(!isset($_REQUEST['method'])) exit('{"status":"fail","msg":"非法访问","code":101}');
if(!isset($_REQUEST['account'])) exit('{"status":"fail","msg":"非法访问","code":101}');

$account = addslashes($_REQUEST['account']);
$sql = "select id from pft_member where account='$account' limit 1";
$GLOBALS['le']->query($sql);
if(!$GLOBALS['le']->fetch_assoc()) exit('{"status":"fail","msg":"无权限访问","code":102}');

$sign = $_REQUEST['sign'];
unset($_REQUEST['sign']);
ksort($_REQUEST);
$token_str = implode('', $_REQUEST);
if(md5($token_str)!=$sign && !$_GET['debug']) exit('{"status":"fail","msg":"签名错误","code":105}');


use \PFT\Db;
Db::Conf($dbConf['remote_1']);
switch(trim($_REQUEST['method'])){
    // 获取类下单相关信息
    case 'ShowINF':
        $type = $_REQUEST['type'] + 0;// 1 获取场馆ID及分区ID  2 场次信息 
        $tid  = $_REQUEST['tid'] + 0;// 
        if(($tid==0) || ($type==0) || ($type==2 && !isset($_REQUEST['date']))) exit('{"status":"fail","msg":"参数错误","code":101}');
        if($type==2) $date = $_REQUEST['date'];
        $response = array('status'=>'success', 'code'=>200, 'venue_id'=>0, 'zone_id'=>0);
        
        $sql = "select zone_id,venus_id from uu_land_f f LEFT JOIN uu_land l ON l.id=f.lid where tid=$tid limit 1";
//        echo $sql;
        if ($_GET['debug']) echo $sql;
        $GLOBALS['le']->query($sql);
        $data = $GLOBALS['le']->fetch_assoc();
//        print_r($data);
        if(!$data) exit(json_encode(array('status'=>'fail', 'code'=>201, 'msg'=>'数据不存在')));
        
        $response['zone_id'] = $zone_id = $data['zone_id'];
        $venue_id = $data['venus_id'];
        if (!$venue_id || !$zone_id)  exit(json_encode(array('status'=>'fail', 'code'=>202, 'msg'=>'数据不存在2')));
        $response['venue_id'] = $venue_id;

        if($type==1) exit(json_encode($response));

        if (isset($_REQUEST['mulit'])) {
            $mulit = $_REQUEST['mulit'] + 0;
            $date_2 = date('Y-m-d', time()+86400*$mulit);
            $sql  = "SELECT id as round_id,bt,et,round_name,use_date,pre_sale from pft_round where venus_id=$venue_id and use_date>='$date' and use_date<'$date_2' and status=0 ORDER BY use_date ASC";
            if ($_GET['debug']) echo $sql;
            $dbResult = Db::fetchAll($sql);
            foreach($dbResult as $row) $response['rounds'][$row['use_date']][] = $row;    
        } else {
            $sql = "SELECT id as round_id,bt,et,round_name,pre_sale FROM pft_round WHERE venus_id=$venue_id and use_date='$date' and status=0";
            $dbResult = Db::fetchAll($sql);
            $response['rounds'] = $dbResult;
        }
        exit(json_encode($response));
        break;
    case 'ShowINFDev':
        $type = $_REQUEST['type'] + 0;// 1 获取场馆ID及分区ID  2 场次信息
        $tid  = $_REQUEST['tid'] + 0;//
        if(($tid==0) || ($type==0) || ($type==2 && !isset($_REQUEST['date']))) exit('{"status":"fail","msg":"参数错误","code":101}');
        if($type==2) $date = $_REQUEST['date'];
        $response = array('status'=>'success', 'code'=>200, 'venue_id'=>0, 'zone_id'=>0);

        $sql = "select zone_id,venus_id from uu_land_f f LEFT JOIN uu_land l ON l.id=f.lid where tid=$tid limit 1";
//        echo $sql;
        $GLOBALS['le']->query($sql);
        $data = $GLOBALS['le']->fetch_assoc();
//        print_r($data);
        if(!$data) exit(json_encode(array('status'=>'fail', 'code'=>201, 'msg'=>'数据不存在')));

        $response['zone_id'] = $zone_id = $data['zone_id'];
        $venue_id = $data['venus_id'];
        if (!$venue_id || !$zone_id)  exit(json_encode(array('status'=>'fail', 'code'=>202, 'msg'=>'数据不存在2')));
        $response['venue_id'] = $venue_id;

        if($type==1) exit(json_encode($response));

        if (isset($_REQUEST['mulit'])) {
            $mulit = $_REQUEST['mulit'] + 0;
            $date_2 = date('Y-m-d', time()+86400*$mulit);
            $sql  = <<<SQL
SELECT id as round_id,bt,et,round_name,use_date from pft_round
where venus_id=$venue_id and use_date>='$date' and use_date<'$date_2' and status=0
 GROUP BY round_name,use_date ORDER BY use_date ASC
SQL;
            if ($_GET['debug']) echo $sql;
            $dbResult = Db::fetchAll($sql);
            foreach($dbResult as $row) $response['rounds'][$row['use_date']][] = $row;
        } else {
            $sql = "SELECT id as round_id,bt,et,round_name FROM pft_round WHERE venus_id=$venue_id and use_date='$date' and status=0";
            $dbResult = Db::fetchAll($sql);
            $response['rounds'] = $dbResult;
        }
        exit(json_encode($response));
        break;
    case 'VenueINF':

        break;
    default:exit('{"status":"fail","msg":"无权限访问","code":101}');break;
}
Db::Close();



class Shows{
    
}






